﻿USE [taobaowangwang]
GO
/****** Object:  Table [dbo].[Shop]    Script Date: 04/09/2011 11:27:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Shop](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[AppKey] [nvarchar](255) NOT NULL,
	[AppSecret] [nvarchar](255) NOT NULL,
	[Name] [nvarchar](255) NULL,
	[Updated] [datetime] NULL,
 CONSTRAINT [PK_Shop] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
) 
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Staff]    Script Date: 04/09/2011 11:27:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Staff](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Nick] [nvarchar](150) NOT NULL,
	[Enabled] [bit] NOT NULL,
	[LastUpdateDate] [datetime] NOT NULL,
	[OnlineTime] [int] NULL,
	[Shop] [int] NOT NULL,
	[QueryNick] [nvarchar](300) NULL,
 CONSTRAINT [PK_Staff] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) 
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ShopManager]    Script Date: 04/09/2011 11:27:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ShopManager](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Nick] [nvarchar](100) NOT NULL,
	[Shop] [int] NOT NULL,
 CONSTRAINT [PK_ShopManager] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) 
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ShopGroup]    Script Date: 04/09/2011 11:27:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ShopGroup](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Manager] [int] NOT NULL,
	[Shop] [int] NOT NULL,
	[GroupName] [nvarchar](150) NOT NULL,
	[GroupMemberList] [nvarchar](1500) NOT NULL,
	[Enabled] [bit] NOT NULL,
	[GroupID] [bigint] NOT NULL,
 CONSTRAINT [PK_ShopGroupMember] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) 
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[StaffStatistics]    Script Date: 04/09/2011 11:27:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StaffStatistics](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Date] [smalldatetime] NOT NULL,
	[ReceiveNum] [bigint] NULL,
	[NonReplyNum] [bigint] NULL,
	[NonReplyCustomIDs] [nvarchar](2500) NULL,
	[Staff] [bigint] NOT NULL,
	[AvgWaitingTimes] [bigint] NULL,
	[OnlineTime] [bigint] NULL,
 CONSTRAINT [PK_StaffStatistics] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) 
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[StaffEvaluation]    Script Date: 04/09/2011 11:27:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StaffEvaluation](
	[StatisticsID] [bigint] NOT NULL,
	[EveluationType] [nvarchar](50) NOT NULL,
	[Count] [int] NOT NULL,
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_StaffEvaluation] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) 
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[StaffChatpeers]    Script Date: 04/09/2011 11:27:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StaffChatpeers](
	[StatisticsID] [bigint] NOT NULL,
	[ChatpeerUID] [nvarchar](150) NOT NULL,
	[ChatDate] [smalldatetime] NOT NULL,
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_StaffChatpeers_1] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) 
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[StaffChatLog]    Script Date: 04/09/2011 11:27:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StaffChatLog](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Statistics] [bigint] NOT NULL,
	[ChatpeerNick] [nvarchar](150) NOT NULL,
	[Direction] [bigint] NOT NULL,
	[Time] [datetime] NOT NULL,
	[Content] [nvarchar](1000) NOT NULL,
	[StaffNick] [nvarchar](150) NOT NULL,
 CONSTRAINT [PK_StaffChatLog] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) 
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Staff_Group]    Script Date: 04/09/2011 11:27:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Staff_Group](
	[Staff] [bigint] NOT NULL,
	[Group] [bigint] NOT NULL,
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_Staff_Group] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) 
) ON [PRIMARY]
GO
/****** Object:  Default [DF_Staff_Enabled]    Script Date: 04/09/2011 11:27:59 ******/
ALTER TABLE [dbo].[Staff] ADD  CONSTRAINT [DF_Staff_Enabled]  DEFAULT ((1)) FOR [Enabled]
GO
/****** Object:  ForeignKey [FK_Staff_Shop]    Script Date: 04/09/2011 11:27:59 ******/
ALTER TABLE [dbo].[Staff]  WITH CHECK ADD  CONSTRAINT [FK_Staff_Shop] FOREIGN KEY([Shop])
REFERENCES [dbo].[Shop] ([Id])
GO
ALTER TABLE [dbo].[Staff] CHECK CONSTRAINT [FK_Staff_Shop]
GO
/****** Object:  ForeignKey [FK_ShopManager_Shop]    Script Date: 04/09/2011 11:27:59 ******/
ALTER TABLE [dbo].[ShopManager]  WITH CHECK ADD  CONSTRAINT [FK_ShopManager_Shop] FOREIGN KEY([Shop])
REFERENCES [dbo].[Shop] ([Id])
GO
ALTER TABLE [dbo].[ShopManager] CHECK CONSTRAINT [FK_ShopManager_Shop]
GO
/****** Object:  ForeignKey [FK_ShopGroupMember_Shop]    Script Date: 04/09/2011 11:27:59 ******/
ALTER TABLE [dbo].[ShopGroup]  WITH CHECK ADD  CONSTRAINT [FK_ShopGroupMember_Shop] FOREIGN KEY([Shop])
REFERENCES [dbo].[Shop] ([Id])
GO
ALTER TABLE [dbo].[ShopGroup] CHECK CONSTRAINT [FK_ShopGroupMember_Shop]
GO
/****** Object:  ForeignKey [FK_ShopGroupMember_ShopManager]    Script Date: 04/09/2011 11:27:59 ******/
ALTER TABLE [dbo].[ShopGroup]  WITH CHECK ADD  CONSTRAINT [FK_ShopGroupMember_ShopManager] FOREIGN KEY([Manager])
REFERENCES [dbo].[ShopManager] ([ID])
GO
ALTER TABLE [dbo].[ShopGroup] CHECK CONSTRAINT [FK_ShopGroupMember_ShopManager]
GO
/****** Object:  ForeignKey [FK_StaffStatistics_Staff]    Script Date: 04/09/2011 11:27:59 ******/
ALTER TABLE [dbo].[StaffStatistics]  WITH CHECK ADD  CONSTRAINT [FK_StaffStatistics_Staff] FOREIGN KEY([Staff])
REFERENCES [dbo].[Staff] ([ID])
GO
ALTER TABLE [dbo].[StaffStatistics] CHECK CONSTRAINT [FK_StaffStatistics_Staff]
GO
/****** Object:  ForeignKey [FK_StaffEvaluation_StaffEvaluation]    Script Date: 04/09/2011 11:27:59 ******/
ALTER TABLE [dbo].[StaffEvaluation]  WITH CHECK ADD  CONSTRAINT [FK_StaffEvaluation_StaffEvaluation] FOREIGN KEY([StatisticsID])
REFERENCES [dbo].[StaffStatistics] ([ID])
GO
ALTER TABLE [dbo].[StaffEvaluation] CHECK CONSTRAINT [FK_StaffEvaluation_StaffEvaluation]
GO
/****** Object:  ForeignKey [FK_StaffChatpeers_StaffStatistics]    Script Date: 04/09/2011 11:27:59 ******/
ALTER TABLE [dbo].[StaffChatpeers]  WITH CHECK ADD  CONSTRAINT [FK_StaffChatpeers_StaffStatistics] FOREIGN KEY([StatisticsID])
REFERENCES [dbo].[StaffStatistics] ([ID])
GO
ALTER TABLE [dbo].[StaffChatpeers] CHECK CONSTRAINT [FK_StaffChatpeers_StaffStatistics]
GO
/****** Object:  ForeignKey [FK_StaffChatLog_Statistics]    Script Date: 04/09/2011 11:27:59 ******/
ALTER TABLE [dbo].[StaffChatLog]  WITH CHECK ADD  CONSTRAINT [FK_StaffChatLog_Statistics] FOREIGN KEY([Statistics])
REFERENCES [dbo].[StaffStatistics] ([ID])
GO
ALTER TABLE [dbo].[StaffChatLog] CHECK CONSTRAINT [FK_StaffChatLog_Statistics]
GO
/****** Object:  ForeignKey [FK_Staff_Group_ShopGroup]    Script Date: 04/09/2011 11:27:59 ******/
ALTER TABLE [dbo].[Staff_Group]  WITH CHECK ADD  CONSTRAINT [FK_Staff_Group_ShopGroup] FOREIGN KEY([Group])
REFERENCES [dbo].[ShopGroup] ([ID])
GO
ALTER TABLE [dbo].[Staff_Group] CHECK CONSTRAINT [FK_Staff_Group_ShopGroup]
GO
/****** Object:  ForeignKey [FK_Staff_Group_Staff]    Script Date: 04/09/2011 11:27:59 ******/
ALTER TABLE [dbo].[Staff_Group]  WITH CHECK ADD  CONSTRAINT [FK_Staff_Group_Staff] FOREIGN KEY([Staff])
REFERENCES [dbo].[Staff] ([ID])
GO
ALTER TABLE [dbo].[Staff_Group] CHECK CONSTRAINT [FK_Staff_Group_Staff]
GO
